layui.use(['form','layer','layedit','laydate','upload'],function(){
    var form = layui.form
    layer = parent.layer === undefined ? layui.layer : top.layer,
        laypage = layui.laypage,
        upload = layui.upload,
        layedit = layui.layedit,
        laydate = layui.laydate,
        $ = layui.jquery;

    var picurl='';
    $("#file").change(function () {
        var formDate = new FormData();
        formDate.append("file",$('#file')[0].files[0]);
        $.ajax({
            url: api1+"upload",
            data:formDate,
            cache: false,
            type:"POST",
            processData: false,
            contentType: false,
            success:function (data) {
                console.log(data);
                $('.iconUrlDisplay').attr('src', data);
                $('.layui-file-display').css('display', 'block');
                $('#picUrl').val(data);
            }
        })
    })

//
    form.on("submit(d-update)",function(data){
        $.ajax({
            type: "POST",
            headers: {
                token :  $.cookie('token')
            },
            url: api+"loms/mg/discount/update",
            data: $('#a-form').serialize(),
            success: function(result){
                console.log(result);
                if(result.code == 1){
                    top.layer.msg("分类信息修改成功！");
                    setTimeout(function(){
                        parent.location.reload();
                    },1000);
                } else {
                    top.layer.msg(result.message);
                }
            }
        });
        return false;
    })



});